﻿using QuanLyNganHangDe.BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanLyNganHangDe.GUI.DuLieu
{
    public partial class FormTooltip : Form
    {
        string _noiDung, _dapAn, _maCauHoi;
        public FormTooltip(string maCauHoi, string noiDung, string DapAn)
        {
            _maCauHoi = maCauHoi;
            _noiDung = noiDung;
            _dapAn = DapAn;
            InitializeComponent();
        }

        private void FormTooltip_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                e.SuppressKeyPress = true;
                this.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormTooltip_Activated(object sender, EventArgs e)
        {

        }

        private void FormTooltip_Shown(object sender, EventArgs e)
        {
            try
            {
                if (_noiDung != null)
                    rtbCauHoi.Load(_noiDung, TXTextControl.StringStreamType.RichTextFormat);
                else
                    MessageBox.Show("Không có dữ liệu nội dung");
                if (_dapAn != null)
                    rtbDapAn.Load(_dapAn, TXTextControl.StringStreamType.RichTextFormat);
            }
            catch (Exception exc)
            {
                MessageBox.Show("Xuất hiện lỗi: " + exc.ToString());
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (BizCauHoi.UpdateContent(_maCauHoi, rtbCauHoi.GetRtfCode(), rtbDapAn.GetRtfCode(), rtbCauHoi.GetPlainText(), rtbDapAn.GetPlainText()) == 1)
            {
                DialogUtils.ShowMessage("Lưu dữ liệu thành công");
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
                DialogUtils.ShowError("Đã có lỗi xảy ra");
        }
    }
}
